#include "CActionBar.h"
#include "SGD Wrappers/CSGD_DirectInput.h"
#include "SGD Wrappers/CSGD_Direct3D.h"

void CActionBar::Init()
{
	for (int i = 0; i < 4; i++)
		for (int j = 0; j < 2; j++)
			m_nKeyPos[i][j] = 0;
}

void CActionBar::Update()
{
	if(CSGD_DirectInput::GetInstance()->KeyPressedEx(DIK_1))
		m_listKeys[0].Execute();
	else if(CSGD_DirectInput::GetInstance()->KeyPressedEx(DIK_2))
		m_listKeys[1].Execute();
	else if(CSGD_DirectInput::GetInstance()->KeyPressedEx(DIK_3))
		m_listKeys[2].Execute();
	else if(CSGD_DirectInput::GetInstance()->KeyPressedEx(DIK_4))
		m_listKeys[3].Execute();
}

void CActionBar::Execute(int nIndex)
{
	m_listKeys[nIndex].Execute();
}

void CActionBar::Render(int nIndex)
{
	m_listKeys[nIndex].Render(m_nKeyPos[nIndex][0] - HOTKEY_HALF_WIDTH, m_nKeyPos[nIndex][1] - HOTKEY_HALF_HEIGHT);
}

void CActionBar::Render()
{
	for(int i = 0; i < 4; i++)
	{
		Render(i);
		CSGD_Direct3D::GetInstance()->SpriteEnd();
		char buffer[2];
		_itoa_s(i+1, buffer, 10);
		CSGD_Direct3D::GetInstance()->DrawText(buffer, m_nKeyPos[i][0], m_nKeyPos[i][1], 128,128,0);
		CSGD_Direct3D::GetInstance()->SpriteBegin();
	}
}

void CActionBar::SetMessage(int nIndex, CMessage *pMessage)
{
	m_listKeys[nIndex].Message(pMessage);
}

void CActionBar::SetPosition(int nIndex, int nPosX, int nPosY)
{
	m_nKeyPos[nIndex][0] = nPosX;
	m_nKeyPos[nIndex][1] = nPosY;
}

void CActionBar::SetImage(int nIndex, char *szImageFile)
{
	m_listKeys[nIndex].ImageID(szImageFile);
}